import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  ManyToOne,
  JoinColumn
} from 'typeorm';
import { Scene } from './Scene';
import { Device } from './Device';

@Entity()
export class SceneAction {
  @PrimaryGeneratedColumn('uuid')
  action_id!: string;

  @Column({ type: 'uuid' })
  scene_id!: string;

  @Column({ type: 'varchar', length: 255 })
  device_id!: string;

  @Column()
  operation!: string;

  @Column('text') // value 可以是任意类型，存为字符串
  value!: string;

  @ManyToOne(() => Scene, scene => scene.actions, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'scene_id' })
  scene!: Scene;

  @ManyToOne(() => Device, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'device_id' })
  device!: Device;
}
